package plus.decl;

import java.util.List;

import plus.B;
import plus.S_Function;
import plus.Type;

public class PT_Func extends TypeSpec {
	private boolean isVoid;
	private List<TypeSpec> domainSpec;
	private TypeSpec rangeSpec;

	public PT_Func(boolean isVoid, List<TypeSpec> domain, TypeSpec range) {
		this.isVoid = isVoid;
		this.domainSpec = domain;
		this.rangeSpec  = range;
	}

	@Override
	public
	Type interpret() {
		S_Function s = new S_Function();
		s.domain = domain();
		s.range = range();
		return Type.fresh(s);
	}
	private Type[] domain() {
		if (domainSpec == null) return null;
		Type[] domain = new Type[domainSpec.size()];
		int i=0;
		for (TypeSpec ts: domainSpec) domain[i++] = ts.interpret();
		return domain;
	}
	private Type range() {
		if (isVoid) return B._void;
		if (rangeSpec == null) return Type.variable();
		return rangeSpec.interpret();
	}
}
